#
# @lc app=leetcode.cn id=454 lang=python3
#
# [454] 四数相加 II
#

# @lc code=start
from collections import defaultdict
from typing import List


class Solution:
    def fourSumCount(self, nums1: List[int], nums2: List[int], nums3: List[int], nums4: List[int]) -> int:
        #将四数之和 转化为两数之和问题
        cnt = defaultdict(int)
        for x in nums1:
            for y in nums2:
                cnt[x+y] += 1
        ans = 0
        for x in nums3:
            for y in nums4:
                tag = -(x + y)
                if tag in cnt:
                    ans += cnt[tag]
        return ans
# @lc code=end

